<template>
    <div>
        <el-table :data="tableData" border stripe
                  :header-cell-class-name="'headerBg'"
                  :header-cell-style="{'text-align':'center'}"
                  :cell-style="{'text-align':'center'}">
            <el-table-column prop="uname" label="用户名" width="120px">
            </el-table-column>
            <el-table-column prop="ubirth" label="用户生日" width="140px">
            </el-table-column>
            <el-table-column prop="ugender" label="性别" width="60px">
            </el-table-column>
            <el-table-column prop="umail" label="用户邮箱" width="180px">
            </el-table-column>
            <el-table-column prop="uphone" label="用户手机号" width="130px">
            </el-table-column>
            <el-table-column prop="usign" label="用户签名" width="300px">
            </el-table-column>
            <el-table-column prop="uidentity" label="用户身份证号" width="200px">
            </el-table-column>
<!--添加一个用户头像的处理-->
            <el-table-column label="处理操作">
                <template slot-scope="scope">
                    <el-popconfirm
                            class="ml-5"
                            confirm-button-text='确定'
                            cancel-button-text='我再想想'
                            icon="el-icon-info"
                            icon-color="red"
                            title="你确定恢复该用户吗？"
                            @confirm="LetPass(scope.row.uid)"
                    >
                        <el-button type="success" slot="reference">恢复 <i class="el-icon-check"></i></el-button>
                    </el-popconfirm>
                    <el-popconfirm
                            class="ml-5"
                            confirm-button-text='确定'
                            cancel-button-text='我再想想'
                            icon="el-icon-info"
                            icon-color="red"
                            title="你确定删除吗？"
                            @confirm="NotLetPass(scope.row.uid)"
                    >
                        <el-button type="danger" slot="reference">删除 <i class="el-icon-close"></i></el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        <div style="padding: 10px 0">
            <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageNum"
                    :page-sizes="[2, 5, 10, 20]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    export default {
        name:"User",
        data(){
            return{
                selectedValueGender:"",
                selectedValue:"",
                flag: false,
                tableData: [],
                total:0,
                pageNum:1,
                pageSize:5,
                uname: "",
                umail:"",
                uphone:"",
                form:{},
                dialogFormVisible:false,
            }
        },
        created() {
            this.load();
        },
        methods:{
            stateFormatGender(row) {
                if (row.ugender === "男") {
                    return '男'
                }
                else  {
                    return '女'
                }
            },
            load(){
                this.request.get("/user/lpage",{
                    params:{
                        pageNum:this.pageNum,
                        pageSize:this.pageSize,
                    }
                }).then(res=>{
                    console.log(res)
                    this.tableData=res.records
                    this.total=res.total
                })

            },
            handleSizeChange(pageSize){
                this.pageSize=pageSize
                this.load()
            },
            handleCurrentChange(pageNum){
                this.pageNum=pageNum
                this.load()
            },
            LetPass(id){
                this.request.get("/user/Nstatus/"+id).then(res=>{
                    if(res){
                        this.$message.success("操作成功")
                        this.dialogFormVisible=false
                        this.load()
                    }else{
                        this.$message.error("操作失败")
                    }
                })
            },
            NotLetPass(id){
                this.request.delete("/user/delete/"+id).then(res=>{
                    if(res){
                        this.$message.success("操作成功")
                        this.dialogFormVisible=false
                        this.load()
                    }else{
                        this.$message.error("操作失败")
                    }
                })
            },
        }
    }
</script>
<style>
    .headerBg{
        background-color: #eee !important;
    }
</style>